package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

@WebServlet("/delClazz2")
public class DelClazz2Servlet extends  HttpServlet{
@Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req,resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String clazz_id=req.getParameter("clazz_id");

    String sql="delete from clazz where id=?";
    Object[] args={clazz_id};
    int row= JdbcUtil.update(sql,args);

    HttpSession session=req.getSession();
    if(row>0){
      session.setAttribute("clazz_msg","删除班级成功");
    }else{
      session.setAttribute("clazz_msg","删除班级失败");
    }
    resp.sendRedirect(req.getContextPath()+"/showClazzes");
  }
}
